<!-- 商品列表 -->
<template>
	<view class="list-box">
		<view class="title-box">
			<view class="title-card">
				<view class="card-top">
					<view class="card-top-left">
						<p>为你省钱</p>
						<p style="font-size: 22rpx;color: #FB3F36;font-weight: 600;">1件即可返利补贴</p>
						<view class="moreBtn" @click="onToScoll">
							查看更多
						</view>
					</view>
					<view class="card-top-right">
						<view v-for="(item,index) in topData" :key="index" @click="toDetail(item.id)" class="card">
							<view class="img-box">
								<image mode="widthFix" :src="item.img" alt="">
									<view class="butie">
										补贴{{((item.price-item.cost)*item.rebate/100).toFixed(2)}}
									</view>
							</view>
							<view class="pirce-box">
								<view class="">
									￥
									<span class="pice">{{item.price}}</span>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="card-bottom">
					<view class="bottom-top">
						<view class="">
							千万补贴
						</view>
						<view class="tip-box">
							买贵必赔
						</view>
					</view>
					<view class="bottoms">
						<view v-for="(item,index) in bottomData" :key="index" @click="toDetail(item.id)"
							class="btm-card">
							<image mode="heightFix" :src="item.img"></image>
							<view class="info">
								<view class="Price">
									￥
									<span style="font-size: 30rpx;">{{item.price}}</span>
								</view>
								<!-- 							<view class="info-two">
								省{{((item.price-item.cost)*item.rebate/100).toFixed(2)}}
							</view> -->
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="category-tabs-wrap">
			<!-- 吸顶 -->
			<view class="u-sticky-wrap" :class="[elClass]" :style="{ height: fixed ? height + 'px' : 'auto'}">
				<view class="u-sticky"
					:style="{ position: fixed ? 'fixed' : 'static', top: stickyTop + 'px', left: left + 'px', width: width == 'auto' ? 'auto' : width + 'px', zIndex: 1109 }">
					<view class="" style="background: #f5f5f5;padding-top: 20rpx;">
						<scroll-view scroll-x class="tabs-content" enable-flex scroll-with-animation
							:scroll-left="scrollLeft">
							<view class="u-flex u-row-cetner u-flex-1 u-col-center">
								<view class="tab-item u-flex-col u-col-center u-row-center"
									v-for="(item, index) in reslist" :key="index" @tap="tabChange(index)">
									<view class="tab-title u-m-y-6" :class="{ 'title-active': detailtab == index }">
										{{ item.name }}
									</view>
									<!-- <view class="nav-line" :class="{ 'line-active':detailtab == index }"></view> -->
								</view>
							</view>
						</scroll-view>
					</view>
				</view>
			</view>
			<view class="">
				<shGoodswWaterFall :rebate="rebate" :ids="ids" ref="waterfall"></shGoodswWaterFall>
			</view>
		</view>
		<!-- 缺省页 -->
		<ljshop-empty v-if="isEmpty" :image="$IMG_URL + '/imgs/empty/empty_goods.png'" tipText="暂无该商品，还有更多好货等着你噢~">
		</ljshop-empty>

		<view class="upward" v-if="isShow" @click="pullTop()"> <u-icon name="arrow-upward" color="#999" size="28">
			</u-icon></view>
	</view>
</template>

<script>
	import shGoodsCardZq from './components/sh-goods-card-zq.vue';
	import shGoodswWaterFall from './components/sh-goods-waterfall.vue'
	import {
		mapMutations,
		mapActions,
		mapState
	} from 'vuex';
	let systemInfo = uni.getSystemInfoSync();
	let historyTag = uni.getStorageSync('searchHistoryArr') ? JSON.parse(uni.getStorageSync('searchHistoryArr')) : [];
	export default {
		components: {
			shGoodsCardZq,
			shGoodswWaterFall
		},
		data() {
			return {
				isShow: false,
				// 吸顶相关
				fixed: false,
				height: 'auto',
				elClass: this.$u.guid(),
				left: 0,
				width: 'auto',
				stickyTop: 0,
				isEmpty: false,
				categoryId: 0,
				loadStatus: 'loadmore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
				order: '',
				rebate: 0,
				reslist: [],
				detailtab: 0,
				currentPage: 0,
				hasmore: true,
				cateId: 0,
				loadStatus: 'loadmore',
				scrollLeft: 0,
				bindId: "",

				onEnd: false,
				goodsList: [],
				topData: [],
				bottomData: [],
				ids: '',
				changed: false
			};
		},
		// 触底加载更多
		onReachBottom() {
			if (!this.$refs.waterfall.onEnd) {
				this.$refs.waterfall.page += 1
				this.$refs.waterfall.getGoodsList()
			}
		},
		onLoad() {
			this.getcate();
			uni.setNavigationBarTitle({
				title: this.$Route.query.name
			})
		},
		onPageScroll(e) {
			if (e.scrollTop > 500) {
				this.isShow = true;
			} else {
				this.isShow = false;
			}
		},
		methods: {
			pullTop() {
				uni.pageScrollTo({
					scrollTop: 0, //滚动到距离顶部为0
					duration: 500 //滚动时长
				})
			},
			getcate() {
				let that = this;
				uni.showLoading({})
				that.$http(
					'common.zhuanqunew',
				).then(res => {

					uni.hideLoading()
					that.bindId = res.bindId
					that.reslist = res.reslist
					that.cateId = that.reslist[0].id;
					// this.getGoodsList();
					this.getTopData()

				});
				uni.stopPullDownRefresh();
				this.isRefresh = true;
			},
			onToScoll() {
				uni.pageScrollTo({
					scrollTop: 300,
					duration: 0
				})
			},
			getTopData() {
				// 获取顶部数据
				this.$http('goods.getScantTop', {})
					.then(res => {
						this.topData = res.scant
						this.bottomData = res.perk
						this.$refs.waterfall.cateId = this.reslist[0].id
						this.ids = res.ids
						// this.$refs.waterfall.getGoodsList()
					})
			},
			tabChange(index) {
				if (this.detailtab == index) return
				if (this.changed) return
				this.changed = true
				this.detailtab = index
				this.cateId = this.reslist[index].id;
				this.$refs.waterfall.onEnd = false
				this.$refs.waterfall.cateId = this.cateId
				this.$refs.waterfall.clear()
				this.scrollLeft = (index - 1) * 60;
				setTimeout(() => {
					this.changed = false
				}, 1000)
			},
			toDetail(e) {
				this.$Router.push({
					path: '/pages/goods/detail',
					query: {
						id: e,
						subsidy: true
					}
				})
			}
		}
	};
</script>

<style lang="scss">
	@mixin vue-flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: $direction;
		/* #endif */
	}

	.u-waterfall {
		@include vue-flex;
		flex-direction: row;
		align-items: flex-start;
	}

	.u-column {
		@include vue-flex;
		flex: 1;
		flex-direction: column;
		height: auto;
	}

	.head-box {
		position: -webkit-sticky;
		position: sticky;
		top: 0;
		z-index: 998;
		background: #fff;
	}

	.menu-category-box,
	.menu-swiper-box {
		position: relative;
		background: #fff;

		.menu-swiper-item {
			background: #fff;
			height: 100%;
			width: 100%;
		}

		.menu-tab-box {
			.tab-list {
				font-size: 26rpx;
				font-weight: 500;
				color: rgba(51, 51, 51, 1);
				margin: 20rpx 0;

				.tab-img {
					width: 80rpx;
					height: 80rpx;
					margin-bottom: 10rpx;

				}

				.tab-text {
					font-size: 26rpx;

				}
			}
		}

		.menu-category-dots {
			display: flex;
			position: absolute;
			left: 50%;
			transform: translateX(-50%);
			bottom: 10rpx;

			.category-dot {
				width: 12rpx;
				height: 12rpx;
				background: #eeeeee;
				border-radius: 50%;
				margin-right: 10rpx;
			}

			.category-dot-active {
				width: 12rpx;
				height: 12rpx;
				background: #e9b461;
				border-radius: 50%;
				margin-right: 10rpx;
			}
		}
	}

	.detailtitle-active {
		color: #fb3f36;
	}

	.imagestyle {
		border-radius: 1rpx;
		width: 750rpx;
		height: 330rpx;


	}

	@mixin vue-flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: $direction;
		/* #endif */
	}

	.category-tabs-wrap {

		// 吸顶
		.u-sticky-wrap {
			background-color: #fff;
		}

		// 瀑布流
		.u-waterfall {
			@include vue-flex;
			flex-direction: row;
			align-items: flex-start;
		}

		.u-column {
			@include vue-flex;
			flex: 1;
			flex-direction: column;
			height: auto;
		}
	}

	// 滑动分类
	.tabs-content {
		white-space: nowrap;

		.tab-item {
			min-height: 60rpx;
			display: inline-block;
			margin: 0 10rpx;

			.nav-line {
				width: 100rpx;
				height: 4rpx;
				background: #fff;
				margin-left: 6rpx;
			}

			.line-active {
				background: #D44C1C;
			}

			.tab-title {
				font-size: 28rpx;
				font-weight: 500;
				color: #333333;
				text-align: center;
			}

			.title-active {
				color: #fb3f36;
				font-weight: 600;
			}

			.tab-des {
				font-size: 26rpx;
				font-weight: 400;
				color: #999999;
				text-align: center;
			}

			.des-active {
				background: linear-gradient(90deg, #e9b461, #eecc89);
				border-radius: 15rpx;
				padding: 2rpx 10rpx;
				color: #ffffff;
			}

		}
	}

	// 顶部盒子
	.title-box {
		width: 100%;
		height: 520rpx;
		background-color: #fb3f36;
		display: flex;
		justify-content: center;
		align-items: center;

		.moreBtn {
			width: 140rpx;
			height: 60rpx;
			text-align: center;
			color: #fff;
			line-height: 60rpx;
			background-color: #fb3f36;
			border-radius: 20rpx;
			margin-top: 40rpx;
		}

		.title-card {
			width: 718rpx;
			height: 454rpx;
			background-color: #fff;
			border-radius: 30rpx;
			display: flex;
			flex-direction: column;

			.card-top {
				flex: 1;
				display: flex;
				background: linear-gradient(180deg, #f6dbd2, #fefaf9);
				border-top-left-radius: 20rpx;
				border-top-right-radius: 20rpx;
				padding-top: 20rpx;

				.card-top-left {
					width: 175rpx;
					height: 100%;
					// background-color: red;
					padding-top: 10rpx;
					margin-left: 10rpx;
				}

				.card-top-right {
					display: flex;
					width: 530rpx;
					justify-content: space-between;

					.card {
						width: 170rpx;
						height: 95%;
						background-color: #ffffff;
						border-radius: 20rpx;
						display: flex;
						flex-direction: column;
						align-items: center;

						.img-box {
							width: 150rpx;
							height: 150rpx;
							// background-color: saddlebrown;
							margin-top: 10rpx;
							border-radius: 20rpx;
							overflow: hidden;
							position: relative;

							.butie {
								position: absolute;
								bottom: 0;
								width: 100%;
								height: 30rpx;
								background: #fb3f36;
								color: #fff;
								text-align: center;
								font-size: 20rpx;
							}

							image {
								width: 100%;
								height: 100%;
							}
						}

						.pirce-box {
							display: flex;
							justify-content: center;
							align-items: center;
							width: 100%;
							height: 50rpx;
							color: #FB3F36;
							font-size: 20rpx;

							// margin-top: 10rpx;
							.pice {
								font-size: 23rpx;
							}

							.butie {
								margin-left: 10rpx;
							}
						}
					}
				}
			}

			.card-bottom {

				flex: 1;
				display: flex;
				flex-direction: column;
				background: linear-gradient(180deg, #fbeede, #fefaf9);
				border-radius: 20rpx;
				padding: 0 20rpx 10rpx 10rpx;

				.bottom-top {
					margin-top: 10rpx;
					display: flex;
					// align-items: center;
					align-items: flex-end;

					.tip-box {
						font-size: 25rpx;
						width: 130rpx;
						height: 35rpx;
						margin-left: 10rpx;
						background-color: red;
						border-radius: 10rpx;
						line-height: 35rpx;
						color: #fff;
						text-align: center;
					}
				}

				.bottoms {
					display: flex;
					// justify-content: space-between;
					height: 100%;
					margin-top: 10rpx;

					.btm-card {
						width: 180rpx;
						height: 170rpx;
						// background-color: red;
						display: flex;
						flex-direction: column;
						// justify-content: center;
						align-items: center;

						image {
							width: 155rpx;
							height: 130rpx;
							border-radius: 10rpx;
						}

						.info {
							margin-top: 10rpx;
							display: flex;
							color: #FB3F36;
							align-items: center;

							.Price {
								font-weight: 600;
								font-size: 20rpx;
								margin-right: 10rpx;
							}

							.info-two {
								width: 70rpx;
								height: 34rpx;
								text-align: center;
								line-height: 34rpx;
								background: #FCD8E2;
								border-radius: 15rpx 15rpx 15rpx 0rpx;
								font-size: 20rpx;
							}
						}
					}
				}
			}
		}
	}
</style>